import request from '@/utils/request'
import Qs from 'qs'
export function list(query) {
  return request({
    method: 'get',
    params: {
      _gp: 'admin.cardOrder',
      _mt: 'list',
      ...query
    }
  })
}

export function active(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'updateStatus',
      ...data
    })
  })
}

export function create(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'create',
      cardOrderDO: JSON.stringify(data)
    })
  })
}

export function update(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'update',
      cardOrderDO: JSON.stringify(data)
    })
  })
}

export function del(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'delete',
      ...data
    })
  })
}

export function detail(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'detail',
      ...data
    })
  })
}

export function cardOrderDetail(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.cardOrder',
      _mt: 'cardOrderDetail',
      ...data
    })
  })
}

export function cardSlaveStatistic(data) {
  return request({
    method: 'post',
    data: Qs.stringify({
      _gp: 'admin.AdminStoreCardStatisticService',
      _mt: 'cardSlaveStatistic',
      ...data
    })
  })
}


export function storeCardSalesExport(timeInfo, storeId) {
  timeInfo = timeInfo && timeInfo !== '' ? timeInfo : ''
  storeId = storeId || ''
  const exportOrderSummaryHref = process.env.HOST + '/excel/storeCardSalesExport'
  const a = document.createElement('a')
  a.setAttribute('href', encodeURI(exportOrderSummaryHref + '?timeInfo=' + timeInfo + '&storeId=' + storeId))
  a.click()
  a.remove()
}
